import pandas as pd
import numpy as np

# 生成一个5x5的随机数
n = np.random.randint(0, 10, size=(5, 5))

print(n)

df = pd.DataFrame(data=n, columns=list("ABCDE"))
print(df)


# 中国省份和省会数据
provinces = [
    "北京市",
    "天津市",
    "河北省",
    "山西省",
    "内蒙古自治区",
    "辽宁省",
    "吉林省",
    "黑龙江省",
    "上海市",
    "江苏省",
    "浙江省",
    "安徽省",
    "福建省",
    "江西省",
    "山东省",
    "河南省",
    "湖北省",
    "湖南省",
    "广东省",
    "广西壮族自治区",
    "海南省",
    "重庆市",
    "四川省",
    "贵州省",
    "云南省",
    "西藏自治区",
    "陕西省",
    "甘肃省",
    "青海省",
    "宁夏回族自治区",
    "新疆维吾尔自治区",
]

capitals = [
    "北京",
    "天津",
    "石家庄",
    "太原",
    "呼和浩特",
    "沈阳",
    "长春",
    "哈尔滨",
    "上海",
    "南京",
    "杭州",
    "合肥",
    "福州",
    "南昌",
    "济南",
    "郑州",
    "武汉",
    "长沙",
    "广州",
    "南宁",
    "海口",
    "重庆",
    "成都",
    "贵阳",
    "昆明",
    "拉萨",
    "西安",
    "兰州",
    "西宁",
    "银川",
    "乌鲁木齐",
]

# 生成随机人口数据(单位：万人)
np.random.seed(42)  # 设置随机种子保证结果可重现
populations = np.random.randint(200, 2000, size=len(provinces))

# 创建DataFrame
china_cities = pd.DataFrame(
    {"provinces": provinces, "cities": capitals, "populations": populations}
)

# 显示前10行数据
print(china_cities.head(10))
print(china_cities.dtypes)
print(china_cities.info())


data = [{"a": 1, "b": 2}, {"a": 5, "b": 10, "c": 20}]

df = pd.DataFrame(data)

print(df)

provinces = china_cities.set_index("provinces")
print(provinces)
# print(provinces.loc[])
print(china_cities.loc[0])
print(china_cities.loc[:5, "cities"])
print(china_cities.iloc[:5, 1])
# print(china_cities.loc[0:4, :"provinces"])
